#include <stdio.h>
#include <stdlib.h>

// 这里先写个链表
typedef struct Node{
    int data;
    struct Node *next;
} Node;

Node *createNode(int data){
    Node *node = (Node*)malloc(sizeof(Node));
    node->data = data;
    node->next = NULL;
    return node;
}

// 这里写个队列用来掌管一切
typedef struct{
    int size;
    Node *front;
    Node *rear;
} Queue;

Queue *initqueue(){
    Queue *queue = (Queue*)malloc(sizeof(Queue));
    queue->size = 0;
    queue->front = queue->rear = NULL;
}


void enqueue(Queue *queue, int value){
    Node *node = createNode(value);
    if (queue->front == NULL){
        queue->front = node;
        queue->rear = node;
    }else{
        queue->rear->next = node;
        queue->rear = queue->rear->next;
    }
    queue->size++;
}

int dequeue(Queue *queue){
    if(queue->front == NULL){
        printf("Queue is empty!\n");
    }else{
        Node *temp = queue->front;
        int n = queue->front->data;
        queue->front = queue->front->next;
        if (queue->size == 0){
            queue->rear = NULL;
        }
        free(temp);
        queue->size--;
        return n;
    }
}



int main(){    
    Queue *queue = initqueue();

    enqueue(queue,12);
    enqueue(queue,33);
    enqueue(queue,37);
    
    printf("%d\n",dequeue(queue));
    printf("%d\n",dequeue(queue));
    printf("%d\n",dequeue(queue));
    printf("%d\n",dequeue(queue));
    return 0;
}